package com.ruoyi.ruonorder.utils;


import com.ruoyi.common.core.domain.R;
import org.springframework.web.bind.annotation.PathVariable;

public class DistanceUtils {


    /**
     * 使用Haversine公式计算两个地理之间的距离
     */
    public static double haversineDistance(double depLongitude,double depLatitude,double toPickUpPassengerLongitude,double toPickUpPassengerLatitude){
        //将角度转换为弧度
        double R = 6371.0;//地球半径,单位公里
        double dLat = Math.toRadians(toPickUpPassengerLatitude - depLatitude);
        double dLon = Math.toRadians(toPickUpPassengerLongitude - depLongitude);
        double lat1 = Math.toRadians(depLatitude);
        double lat2 = Math.toRadians(toPickUpPassengerLatitude);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)+Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
        double c = 2 * Math.atan2(Math.sqrt(a),Math.sqrt(1 - a));
        return R * c;
    }
}
